Skip to content

🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation#6

Merged
Marius Storhaug (MariusStorhaug) merged 5 commits intomainfrom
reserved
Apr 29, 2026
Merged

🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation#6
Marius Storhaug (MariusStorhaug) merged 5 commits intomainfrom
reserved

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

ConvertFrom-Lua now validates that bare identifier keys and variable names are not Lua reserved words, throwing a clear error by default. A new -SkipValidation switch allows lenient import of out-of-spec data, emitting per-occurrence warnings instead. Enum string serialization no longer double-escapes backslashes.

Changed: Reserved word validation on deserialization

ConvertFrom-Lua now rejects bare reserved words used as table keys or assignment variable names — matching the Lua 5.4 §3.1 grammar rules. Previously, invalid Lua like { end = 1 } or while = 42 was silently parsed.

# Default — throws a terminating error
ConvertFrom-Lua -InputObject '{ end = 1 }'
# Error: Reserved word 'end' cannot be used as a bare identifier key in a Lua table.
#        Use bracket notation: [\"end\"] = value.

Bracket-notation keys with reserved word strings remain fully supported:

ConvertFrom-Lua -InputObject '{ [\"end\"] = 1, [\"while\"] = 2 }' -AsHashtable
# Returns: @{ end = 1; while = 2 }

New: -SkipValidation switch for lenient import

When importing data that may not be spec-compliant, use -SkipValidation to suppress errors. Each reserved word occurrence produces its own warning, and parsing continues normally.

ConvertFrom-Lua -InputObject '{ end = 1, while = 2 }' -AsHashtable -SkipValidation
# WARNING: Reserved word 'end' used as a bare identifier key at position 2.
# WARNING: Reserved word 'while' used as a bare identifier key at position 11.
# Returns: @{ end = 1; while = 2 }

Fixed: Enum string escaping no longer double-escapes backslashes

ConvertTo-Lua -EnumsAsStrings previously produced \\\\ instead of \\ for backslashes in enum string representations due to an incorrect -replace pattern.

Technical Details

  • ConvertFrom-Lua.ps1: Added -SkipValidation switch parameter, threaded to ConvertFrom-LuaTable via -SkipValidation:$SkipValidation.
  • ConvertFrom-LuaTable.ps1: Added -SkipValidation parameter. Stored as $script:luaSkipValidation for use by recursive parser functions. Added $reservedWords array and validation after variable name extraction in the assignment parsing path — throws or warns based on skip flag.
  • Read-LuaTable.ps1: Added $reservedWords array and validation after bare identifier + = detection — throws or warns based on $script:luaSkipValidation.
  • ConvertTo-LuaTable.ps1: Fixed enum escaping: -replace '\\', '\\\\'-replace '\\', '\\'.
  • return keyword note: return is consumed as a leading keyword before assignment detection (for return { ... } patterns), so return = 42 triggers a different parse error rather than the reserved word check. Tests use while as the second assignment variable test word.
  • Tests: 8 new tests — 5 for default throw behavior (bare table keys ×2, bracket notation positive, assignment variables ×2), 3 for -SkipValidation (bare key warning, assignment warning, multiple warnings with count assertion)."

@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Fail ❌
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

Super-linter detected linting errors

For more information, see the GitHub Actions workflow run

Powered by Super-linter

POWERSHELL

�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidLongLines                    Warning      Read-LuaTa 94    Line exceeds
                                                 ble.ps1          the configure
                                                                  d maximum len
                                                                  gth of 150 ch
                                                                  aracters


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidLongLines                    Warning      ConvertFro 90    Line exceeds
                                                 m-Lua.ps1        the configure
                                                                  d maximum len
                                                                  gth of 150 ch
                                                                  aracters

…e error message for reserved words in Read-LuaTable
@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Fail ❌
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

Super-linter detected linting errors

For more information, see the GitHub Actions workflow run

Powered by Super-linter

POWERSHELL

�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSUseConsistentIndentation          Warning      Read-LuaTa 95    Indentation n
                                                 ble.ps1          ot consistent


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAlignAssignmentStatement          Warning      ConvertFro 91    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      ConvertFro 93    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      ConvertFro 94    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned

…onvertFrom-Lua hashtable; resolve indentation inconsistency in Read-LuaTable by inlining throw message
@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

@MariusStorhaug Marius Storhaug (MariusStorhaug) marked this pull request as ready for review April 29, 2026 08:02
Copilot AI review requested due to automatic review settings April 29, 2026 08:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens ConvertFrom-Lua parsing to detect Lua reserved words when they are used as bare identifier table keys or assignment variable names, with a new -SkipValidation switch to downgrade those errors to warnings for lenient imports. It also attempts to fix enum string serialization to avoid double-escaping backslashes.

Changes:

  • Add -SkipValidation to ConvertFrom-Lua and thread it into the private parser via script-scoped state.
  • Validate reserved words in Read-LuaTable (table keys) and ConvertFrom-LuaTable (assignment variables), erroring by default or warning when -SkipValidation is used.
  • Adjust enum string escaping logic in ConvertTo-LuaTable and add tests covering strict/warn behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Lua.Tests.ps1 Adds tests for reserved-word validation and -SkipValidation warning behavior.
src/functions/public/Lua/ConvertFrom-Lua.ps1 Adds -SkipValidation and passes it into the private parser.
src/functions/private/Read-LuaTable.ps1 Adds reserved-word validation for bare identifier keys inside table constructors.
src/functions/private/ConvertFrom-LuaTable.ps1 Adds reserved-word validation for assignment variable names and stores skip flag in script scope.
src/functions/private/ConvertTo-LuaTable.ps1 Modifies enum string escaping behavior for backslashes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/functions/private/Read-LuaTable.ps1
Comment thread src/functions/private/ConvertFrom-LuaTable.ps1
Comment thread src/functions/private/ConvertTo-LuaTable.ps1
…Lua §3.1; add tests for capitalized identifiers (End, While)
@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit d532ebf into main Apr 29, 2026
39 checks passed
@github-actions
Copy link
Copy Markdown

✅ New release: PowerShell Gallery - Lua 1.0.1

@github-actions
Copy link
Copy Markdown

✅ New release: GitHub - Lua v1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate reserved words in ConvertFrom-Lua with -SkipValidation for lenient import

2 participants